#ifndef CMD_VIEW_H
#define CMD_VIEW_H

#include "cmd_node.h"
#include "cmd_executor.h"
#include "cmd_history.h"


#include <map>

#include <boost/iterator/iterator_facade.hpp> 

namespace vpm
{
	namespace cmo 
	{		
		class CmdViewAccess;

		class CmdView 
		{
			//Map the command to the executor. 
			typedef std::map<std::string, CmdExecutorPtr> CmdExecutorMap;					

		public:

			CmdView(const std::string & viewName= "default");

			void add_command(const std::string & cmd, CmdExecutorPtr pExecutor);

			void add_command(CmdExecutorPtr pExecutor);

			template <class T> 
				void add_command(const std::string & cmd )
				{
					CmdExecutorPtr executor(new T()); 
					this->add_command(cmd,executor);
				}

			std::string view_name() const 
			{
				return m_viewName;
			}

			void view_prompt(const std::string & prompt)
			{
				m_viewPrompt = prompt;
			}

			const std::string & view_prompt() const 
			{
				return m_viewPrompt;				
			}

			void set_view_user(const std::string & user)
			{
				m_viewUser = user; 
			}

			void set_view_password(const std::string & pass)
			{
				m_viewPass = pass; 				
			}
			void reset()
			{
				m_lastNode  = m_rootNode; 
			}
		
		public:
			//these functions used on parse phrase. 

			void add_keyword(const std::string & key, CmdNode::NodeType type,CmdExecutorPtr pExecutor);		

			//must the last word of the command. can add action here.
			void add_action(CmdExecutorPtr pExecutor);

		private:
			friend class CmdViewAccess;
			friend class CmdUserSession;

			CmdNodePtr m_lastNode; 			
			CmdNodePtr m_rootNode;
			CmdExecutorMap m_cmdExecutors;
		
			std::string m_viewName; 
			std::string m_viewPrompt; 
			std::string m_viewUser; 
			std::string m_viewPass; 			
		};

		typedef boost::shared_ptr<CmdView> CmdViewPtr;
	}
}

#endif //

